/*
* $Id: EventManager.cpp 31 2010-02-17 16:55:56Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "EventManager.h"

CEventManager::CEventManager(){}
CEventManager::~CEventManager(){}

void CEventManager::SendEvent(int nIdEvent){
	for(std::vector<ISubscriber*>::iterator it = m_aEventSubscribers[nIdEvent].begin(); it != m_aEventSubscribers[nIdEvent].end(); it++){
		(*it)->EventHandler();
	}
}

void CEventManager::SubscribeEvent(ISubscriber* pSubscriber, int nIdEvent){
	m_aEventSubscribers[nIdEvent].push_back(pSubscriber);
}

void CEventManager::UnSubscribeEvent(ISubscriber* pSubscriber, int nIdEvent){
	for(std::vector<ISubscriber*>::iterator it = m_aEventSubscribers[nIdEvent].begin(); it != m_aEventSubscribers[nIdEvent].end(); it++){
		if(*it == pSubscriber){
			m_aEventSubscribers[nIdEvent].erase(it);
			break;
		}
	}
}

void CEventManager::Free(){
	delete this;
}
